import request from '/@/utils/request'

// 工作流保存
export function saveWorkflow(data: any) {
  return request({
    url: '/workflow/save',
    method: 'post',
    data
  })
}

// 工作流分页查询
export function getWorkflowPage(data: any) {
  return request({
    url: '/workflow/page',
    method: 'post',
    data
  })
}

// 获取工作流列表
export function getWorkflowList(data: any) {
  return request({
    url: '/workflow/list',
    method: 'post',
    data
  })
}

// 删除工作流
export function deleteWorkflow(id: string) {
  return request({
    url: `/workflow/delete`,
    method: 'delete',
    data: {
      id
    }
  })
}

// 启动工作流实例
export function startWorkflowInstance(data: any) {
  return request({
    url: '/workflow/start',
    method: 'post',
    data
  })
}

// 获取我的工作流实例
export function getMyWorkflowInstances(data: any) {
  return request({
    url: '/workflow/instance/startByMyself',
    method: 'post',
    data
  })
}

// 获取工作流实例详情
export function getWorkflowInstanceDetail(id: number) {
  return request({
    url: `/workflow/instance/findDetailById`,
    method: 'post',
    data: {
      id
    }
  })
}

// 取消工作流实例
export function cancelWorkflowInstance(data: any) {
  return request({
    url: `/workflow/instance/cancel`,
    method: 'post',
    data
  })
}

// 获取待我审批的工作流实例
export function getPendingApprovals(data: any) {
  return request({
    url: '/workflow/instance/findPenddingApprove',
    method: 'post',
    data
  })
}

// 审批通过
export function approveWorkflow(data: any) {
  return request({
    url: '/workflow/node/approve',
    method: 'post',
    data
  })
}

// 审批拒绝
export function rejectWorkflow(data: any) {
  return request({
    url: '/workflow/node/reject',
    method: 'post',
    data
  })
}

// 转办工单
export function transferWorkflow(data: any) {
  return request({
    url: '/workflow/node/transfer',
    method: 'post',
    data
  })
}

// 添加评论
export function addComment(data: any) {
  return request({
    url: '/workflow/node/comment',
    method: 'post',
    data
  })
}

// 获取我审批过的工作流实例
export function getApprovedByMe(data: any) {
  return request({
    url: '/workflow/instance/findApprovedByMe',
    method: 'post',
    data
  })
}
